package com.asiainfo.complier.editor;

import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.JTabbedPane;

public class ToolTipJTabbedPane extends JTabbedPane {

	/**
	 * ToolTipJTabbedPane
	 */

	public ToolTipJTabbedPane() {
		super();
	}

	private static final long serialVersionUID = 6734594302314701487L;

	public String getToolTipText(MouseEvent event) {
		super.getToolTipText(event);
		Point p = event.getPoint();
		int index = indexAtLocation(p.x, p.y);
		if (index != -1) {
			CoderEditor key = (CoderEditor) getComponentAt(index);
			String tip = key.getCodeInfo().getFilePath();
			return getShortPath(tip);
		} else {
			return "";
		}
	}

	private String getShortPath(String tip) {
		int size = tip.length();
		int offset = 70;
		if (size > offset) {
			int pos = size % offset == 0 ? size / offset : (1 + size / offset);
			String str = "<html>";
			for (int i = 0; i < pos; i++) {
				int index = i * offset;
				int eIndex = index + offset;
				if (eIndex >= size)
					eIndex = size;
				str += tip.substring(index, eIndex) + "<br/>";
			}
			str += "</html>";
			return str;
		} else {
			return tip;
		}

	}
}
